#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <unixio.h>
#include <math.h>
#include <sys.h>
#include <string.h>

#include "ports.h"
#include "msx2lib.h"
#include "map.h"

#asm
    
global _waitvdp
_waitvdp:
	di
	ld a,2
	out (0x99),a
	ld a, 0x8f
	out (0x99),a

1:  in a,(0x99)
	rrca
	jp c, 1b

	xor a
	out (0x99),a
	ld a, 0x8f
	out (0x99),a
	ei
	ret
	
#endasm


extern uint shadow0[];
extern uint shadow1[];

uint window_coords[WMAX_X*WMAX_Y];

char currentpage;

extern uint* shadowbuff;

void init_sc5_draw(void)
{
	uint	i,j;
	// uint	*p;
	
    setpage(0);
    currentpage = 0;
	shadowbuff = shadow1;
	
	memset((char*)shadow0,255,2*WMAX_X*WMAX_Y);
	memset((char*)shadow1,255,2*WMAX_X*WMAX_Y);
	
	// p = window_coords;
	for	(j=0;j<WMAX_Y;j++)
		for	(i=0;i<WMAX_X;i++)
			window_coords[j*WMAX_Y+i] = ((j*8)<<8)+(i*8);
	
}



void sc5_draw_map(void)
{
    static char k;

    if (k&1)
    {
		setpage(0);
		currentpage = 1;
		calculate();		// calculate views
		shadowbuff = shadow1;
    }
    else
    {
		setpage(1);
		currentpage = 0;
		calculate();		// calculate views
		shadowbuff = shadow0;
    }
    k++;
}
